package msi.gama.gui.views;

import msi.gama.common.util.GuiUtils;
import msi.gama.gui.swt.SwtGui;
import msi.gama.gui.swt.perspectives.ModelingPerspective;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveListener;
import org.eclipse.ui.IWorkbenchPage;

// FIXME minhvv create new DisplayView for testing Java3D
public class Java3DDisplayView extends LayeredDisplayView {

	public static final String ID = GuiUtils.JAVA3D_VIEW_ID;

	@Override
	protected Composite createSurfaceComposite() {

		surfaceComposite = new Composite(parent, SWT.EMBEDDED);

		perspectiveListener = new IPerspectiveListener() {

			boolean previousState = false;

			@Override
			public void perspectiveChanged(final IWorkbenchPage page, final IPerspectiveDescriptor perspective,
				final String changeId) {}

			@Override
			public void perspectiveActivated(final IWorkbenchPage page, final IPerspectiveDescriptor perspective) {
				if ( perspective.getId().equals(ModelingPerspective.ID) ) {
					if ( getOutput() != null && getOutput().getSurface() != null ) {
						previousState = getOutput().getSurface().isPaused();
						getOutput().getSurface().setPaused(true);
					}
					if ( overlay != null && layersOverlay != null ) {
						overlay.hide();
						layersOverlay.hide();
					}
				} else {
					if ( getOutput() != null && getOutput().getSurface() != null ) {
						getOutput().getSurface().setPaused(previousState);
					}
					if ( overlay != null && layersOverlay != null ) {
						overlay.update();
						layersOverlay.update();
					}
				}
			}
		};
		SwtGui.getWindow().addPerspectiveListener(perspectiveListener);
		return surfaceComposite;
	}
}
